import axios from 'axios'
import Vue from 'vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
// 请求拦截器
axios.interceptors.request.use((config) => {

  NProgress.start()
  // 请求添加token
  var token = window.sessionStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  console.log(config)
  return config
}, (error) => {
  return Promise.reject(error)
})

// 响应拦截器
axios.interceptors.response.use((response) => {
  NProgress.done()
  return response
}, (error) => {
  return Promise.reject(error)
})

// 接口可以写在这里
// export const login = param => {
//   return axios.post('login', param).then(res => res.data)
// }

Vue.prototype.$http = axios
